package com.zj.study.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 赵赳
 * @since 2022/6/30 15:46
 */
public class RegexPhoneUtil {

  private final static String REGEX_PHONE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";

  /**
   * 校验手机号格式是否正确
   *
   * @param phone 号码
   * @return 格式是否正确
   */
  public static Boolean regexPhone(String phone) {
    boolean b;
    if (phone.length() != 11) {
      b = false;
    } else {
      Pattern p = Pattern.compile(REGEX_PHONE);
      Matcher m = p.matcher(phone);
      b = m.matches();
    }
    return b;
  }

}
